package com.songlanyun.modules.rabbitmq.mq.consumer;

import com.alibaba.fastjson.JSONObject;
import com.rabbitmq.client.Channel;
import com.songlanyun.modules.integralrecord.entity.IntegralRecord;
import com.songlanyun.modules.integralrecord.service.IntegralRecordService;
import com.songlanyun.modules.rabbitmq.service.MessageHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * 获取使用积分
 */
@Component
@Slf4j
public class IntegralRecordConsumer extends BaseConsumer {

    @Autowired
    private IntegralRecordService integralRecordService;

    @Override
    protected void process(Message message) {
        JSONObject msgBody = MessageHelper.msgToObj(message, JSONObject.class);
        IntegralRecord record = JSONObject.toJavaObject(msgBody, IntegralRecord.class);

        integralRecordService.inner(record);

    }

    //TODO 获取积分暂不使用mq发送消息
//    @RabbitListener(queues = MqConstant.IntegralRecordSendMessageConstant.INTEGRAL_RECORD_SEND_MESSAGE_QUEUE)
    public void consume(Message message, Channel channel) throws IOException {
        super.handle(message, channel);
    }
}
